<?php
defined('SYSPATH') or die('No direct script access.');

class Controller_Admin_Admin extends Controller_Template
{
    public $template = 'templates/admin/admin';

    /**
     * Initialize properties before running the controller methods (actions),
     * so they are available to our action.
     */
    public function before()
    {
        if(!Auth::instance()->logged_in()) {
          if ($this->request->controller() == 'Auth' && $this->request->action() == 'login') {
//            Controller::redirect('admin');
          } else{
            Controller::redirect('admin/auth/login');
          }
        }
        // Run anything that need ot run before this.
        parent::before();
        $this->auto_render = ! $this->request->is_ajax();
        if($this->auto_render)
        {
            // Initialize empty values
            $this->template->title            = '';
            $this->template->meta_keywords    = '';
            $this->template->meta_description = '';
            $this->template->meta_copywrite   = '';
            $this->template->menu             = Auth::instance()->logged_in() ? View::factory('templates/admin/menu', array('controller' => $this->request->controller())): '';
            $this->template->content          = '';
            $this->template->styles           = array();
            $this->template->scripts          = array();
        }
    }

    /**
     * Fill in default values for our properties before rendering the output.
     */
    public function after()
    {
        if($this->auto_render)
        {
            // Define defaults
            $styles = array(
                'http://cdn.oesmith.co.uk/morris-0.4.3.min.css' => 'screen',
                'assets/font/admin/font-awesome/css/font-awesome.css' => 'screen',
                'assets/css/admin/sb-admin.css' => 'screen',
                'assets/css/admin/bootstrap.css' => 'screen',

            );
            $scripts = array(
                'assets/js/admin/tablesorter/tables.js',
                'assets/js/admin/tablesorter/jquery.tablesorter.js',
                'assets/js/admin/morris/chart-data-morris.js',
                'http://cdn.oesmith.co.uk/morris-0.4.3.min.js',
                'http://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js',
                'assets/js/bootstrap.min.js',
                'assets/js/jquery.min.js',
            );

            // Add defaults to template variables.
            $this->template->styles  = array_reverse(array_merge($this->template->styles, $styles));
            $this->template->scripts = array_reverse(array_merge($this->template->scripts, $scripts));
        }

        // Run anything that needs to run after this.
        parent::after();
    }
}